package com.d3works.apps.supplychain.service.batch;

import com.d3works.apps.account.db.Move;
import com.d3works.apps.base.db.repo.BatchRepository;
import com.d3works.apps.base.service.administration.AbstractBatch;
import com.d3works.apps.sale.db.SaleOrder;
import com.d3works.apps.stock.db.StockMove;
import com.d3works.apps.supplychain.service.SaleOrderInvoiceService;
import com.d3works.inject.Beans;

public abstract class BatchStrategy extends AbstractBatch {

  protected SaleOrderInvoiceService saleOrderInvoiceService;

  protected BatchStrategy() {
    super();
  }

  protected BatchStrategy(SaleOrderInvoiceService saleOrderInvoiceService) {
    super();
    this.saleOrderInvoiceService = saleOrderInvoiceService;
  }

  protected void updateSaleOrder(SaleOrder saleOrder) {

    saleOrder.addBatchSetItem(Beans.get(BatchRepository.class).find(batch.getId()));

    incrementDone();
  }

  protected void updateStockMove(StockMove stockMove) {

    stockMove.addBatchSetItem(Beans.get(BatchRepository.class).find(batch.getId()));

    incrementDone();
  }

  protected void updateAccountMove(Move move, boolean incrementDone) {

    move.addBatchSetItem(Beans.get(BatchRepository.class).find(batch.getId()));

    if (incrementDone) {
      incrementDone();
    } else {
      checkPoint();
    }
  }

  protected void setBatchTypeSelect() {
    this.batch.setBatchTypeSelect(BatchRepository.BATCH_TYPE_SUPPLYCHAIN_BATCH);
  }
}
